const { envList } = require("../../envList");
const { QuickStartPoints, QuickStartSteps } = require("./constants");
const solarTerms = [
  { name: '立春', prename: '大寒', postname: '雨水', date: new Date('2024/02/04') },
  { name: '雨水', prename: '立春', postname: '惊蛰', date: new Date('2024/02/19') },
  { name: '惊蛰', prename: '雨水', postname: '春分', date: new Date('2024/03/5') },
  { name: '春分', prename: '惊蛰', postname: '清明', date: new Date('2024/03/20') },
  { name: '清明', prename: '春分', postname: '谷雨', date: new Date('2024/04/4') },
  { name: '谷雨', prename: '清明', postname: '立夏', date: new Date('2024/04/19') },
  { name: '立夏', prename: '谷雨', postname: '小满', date: new Date('2024/05/5') },
  { name: '小满', prename: '立夏', postname: '芒种', date: new Date('2024/05/20') },
  { name: '芒种', prename: '小满', postname: '夏至', date: new Date('2024/06/5') },
  { name: '夏至', prename: '芒种', postname: '小暑', date: new Date('2024/06/21') },
  { name: '小暑', prename: '夏至', postname: '大暑', date: new Date('2024/07/6') },
  { name: '大暑', prename: '小暑', postname: '立秋', date: new Date('2024/07/22') },
  { name: '立秋', prename: '大暑', postname: '处暑', date: new Date('2024/08/7') },
  { name: '处暑', prename: '立秋', postname: '白露', date: new Date('2024/08/22') },
  { name: '白露', prename: '处暑', postname: '秋分', date: new Date('2024/09/7') },
  { name: '秋分', prename: '白露', postname: '寒露', date: new Date('2024/9/22') },
  { name: '寒露', prename: '秋分', postname: '霜降', date: new Date('2024/10/8') },
  { name: '霜降', prename: '寒露', postname: '立冬', date: new Date('2024/10/23') },
  { name: '立冬', prename: '寒露', postname: '小雪', date: new Date('2024/11/7') },
  { name: '小雪', prename: '立冬', postname: '大雪', date: new Date('2024/11/22') },
  { name: '大雪', prename: '小雪', postname: '冬至', date: new Date('2024/12/6') },
  { name: '冬至', prename: '大雪', postname: '小寒', date: new Date('2024/12/21') },
  { name: '小寒', prename: '冬至', postname: '大寒', date: new Date('2024/1/5') },
  { name: '大寒', prename: '小寒', postname: '立春', date: new Date('2024/1/20') }
];
Page({
  data: {
    knowledgePoints: QuickStartPoints,
    steps: QuickStartSteps,
    currentSolarTerm: '',
    preSolarTerm: '',
    postSolarTerm: '',
  },
  imageTap1(){
    wx.navigateTo({
      url: '../spring/spring',
    })
  },
  imageTap2(){
    wx.navigateTo({
      url: '../summer/summer',
    })
  },
  imageTap3(){
    wx.navigateTo({
      url: '../autumn/autumn',
    })
  },
  imageTap4(){
    wx.navigateTo({
      url: '../winter/winter',
    })
  },
  onLoad() {
    this.checkSolarTerm();
  },
  checkSolarTerm() {
    const currentDate = new Date();
    for (const solarTerm of solarTerms) {
      if (currentDate == solarTerm.date) {
        this.setData({
          currentSolarTerm: solarTerm.name,
        });
      } else {
        this.setData({
          currentSolarTerm: '今天不是二十四节气中的一天！',
        });
        break;
      }
    }
    for (const solarTerm of solarTerms) {
      if (currentDate >= solarTerm.date) {
        this.setData({
          preSolarTerm: solarTerm.name,
        });
      } else {
        break;
      }
    }
    for (const solarTerm of solarTerms) {
      if (solarTerm.date <= currentDate) {
        this.setData({
          postSolarTerm: solarTerm.postname,
        });
      } else {
        break;
      }
    }
  }
});
